package com.example.mapper;

import com.example.pojo.Equipment;
import com.example.pojo.EquipmentOrder;
import org.apache.ibatis.annotations.*;

import java.sql.Timestamp;
import java.util.List;


@Mapper
public interface EquipmentMapper {

    //查询所有器械
    List<Equipment> findAll();

    /**
     * 根据id查询器材
     * @param equipmentId
     * @return
     */
    @Select("select * from equipment where equipment_id=#{equipmentId}")
    Equipment getById(@Param("equipmentId") Integer equipmentId);
    //根据 id 删除器械
    Boolean deleteByEquipmentId(Integer equipmentId);

    //添加器材
    Boolean insertEquipment(Equipment equipment);

    //根据 id 修改器械信息
    Boolean updateEquipmentByEquipmentId(Equipment equipment);

    //根据 id 查询器械
    List<Equipment> selectByEquipmentId(Integer equipmentId);

    //查询器械总数
    Integer selectTotalCount();

    /**
     * 查询所有空闲器材
     * @return
     */
    List<Equipment> findRelaxEquipment();

    /**
     * 修改器材空闲状态
     * @param equipmentId
     * @return
     */
    @Update("update equipment set equipment_relax = '0' where equipment_id = #{equipmentId}")
    int updateStatus(Integer equipmentId);

    /**
     * 产生预定单
     * @return
     */
    Boolean insertEquipmentOrder(EquipmentOrder order);

    @Update("update equipment_order set use_time = #{useTime} where equipment_order_id = #{equipmentOrderId}")
    int updateTime(@Param("useTime") Timestamp useTime, @Param("equipmentOrderId") Integer equipmentOrderId);

    /**
     * 查询个人的预定信息
     * @param userId
     * @return
     */
    @Select("select * from equipment_order where user_id=#{userId}")
    List<EquipmentOrder> getByUserId(@Param("userId") Integer userId);

    /**
     * 退订
     * @param equipmentId
     * @return
     */
    @Delete(("delete from equipment_order where equipment_order_id = #{equimentOrderId}"))
    void deleteOrderedEquipment(Integer equipmentId);

    /**
     * 退订后修改状态
     * @param equipmentId
     * @return
     */
    @Update("update equipment set equipment_relax = '1' where equipment_id = #{equipmentId}")
    int updateStatusAfterExit(Integer equipmentId);

    /**
     * 查询单个订单
     * @param equipmentOrderId
     * @return
     */
    @Select("select * from equipment_order where equipment_order_id=#{equipmentOrderId}")
    EquipmentOrder getOrder(Integer equipmentOrderId);

}
